﻿using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;

namespace OpenGameEngine.Helper.Serializers
{
    public static class BinaryFile
    {
        public static void Serialize(Object objToSerialize, String filePath)
        {
            FileStream fs = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write);
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(fs, objToSerialize);
            fs.Close();
        }

        public static object Deserialize(String filePath)
        {
            FileStream fs = File.Open(filePath, FileMode.Open, FileAccess.Read);
            BinaryFormatter bf = new BinaryFormatter();
            Object o = bf.Deserialize(fs);
            fs.Close();
            return o;
        }
    }
}
